<?php
class SellerModel extends BaseModel {
	var $table = 'seller';
	var $_page_rows = 20;

	/* 插入数据 */
	function post($data) {
		$time = time();
		if(!isset($data["username"])){$data["username"]='';}
		if(!isset($data["sellername"])){$data["sellername"]='';}		
		if(!isset($data["picture"])){$data["picture"]='';}		
		if(!isset($data["sellerphone"])){$data["sellerphone"]='';}
		if(!isset($data["selleraddress"])){$data["selleraddress"]='';}		
		if(!isset($data["sellerurl"])){$data["sellerurl"]='';}		
		if(!isset($data["sellermap"])){$data["sellermap"]='';}
		if(!isset($data["area"])){$data["area"]='';}		
		
		return $this->IU_Sql_Exe(array (
			'data' => array (
				'user_name' => $data["username"],
				'sellername' => $data["sellername"],
				'picture' => $data["picture"],				
				'sellerphone' => $data["sellerphone"],
				'selleraddress' => $data["selleraddress"],
				'sellerurl' => $data["sellerurl"],
				'sellermap' => $data["sellermap"],
				'area' => $data["area"],
				'add_time' => "$time"
			),
			'mode' => 'INSERT'
		));
	}

	function show() {
		//分页时，一定是先调用page函数，再调用S_Sql_Exe函数
		$info['page'] = $this->Page(array (
			'conditions' => '',
			'url' => 'admin/?app=seller&act=index'
		));
		$info['data'] = $this->S_Sql_Exe(array (
			'fields' => '*',
			'conditions' => '',
			'order' => 'add_time desc',
			'limit' => $info['page']['sql_limit']
		));
		return $info;
	}

	/* 删除数据 */
	function del($id = '') {
		return $this->D_Sql_Exe(array (
			'conditions' => "id = '{$id}' "
		));
	}

	 /* 修改数据 */
	function editaction($id = '', $data = '') {
		$time = time();
		if(!isset($data["username"])){$data["username"]='';}
		if(!isset($data["sellername"])){$data["sellername"]='';}		
		if(!isset($data["picture"])){$data["picture"]='';}		
		if(!isset($data["sellerphone"])){$data["sellerphone"]='';}
		if(!isset($data["selleraddress"])){$data["selleraddress"]='';}		
		if(!isset($data["sellerurl"])){$data["sellerurl"]='';}		
		if(!isset($data["sellermap"])){$data["sellermap"]='';}
		if(!isset($data["area"])){$data["area"]='';}		
					
		return $this->IU_Sql_Exe(array (
			'data' => array (
				'user_name' => $data["username"],
				'sellername' => $data["sellername"],
				'picture' => $data["picture"],					
				'sellerphone' => $data["sellerphone"],
				'selleraddress' => $data["selleraddress"],
				'sellerurl' => $data["sellerurl"],
				'sellermap' => $data["sellermap"],
				'area' => $data["area"],
				'add_time' => "$time"
			),
			'mode' => 'UPDATE',
			'conditions' => "id = '{$id}' "
		));
	}

	/* 通过id取出一条数据 */
	function oneshow($id = '') {
		$info = $this->S_Sql_Exe(array (
			'fields' => '*',
			'conditions' => "id='{$id}'",
			'return' => 'one'
		));
		return $info;
	}
}
?>